package com.yuw.Filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "EncodingFilter",value = "/")
public class EncodingFilter implements Filter {

    //销毁·资源回收
    public void destroy() {
    }

    //逻辑处理
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        // 设置编码格式
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        chain.doFilter(req, resp);
    }

    //将当前的请求传递给后面的服务器
    public void init(FilterConfig config) throws ServletException {

    }

}
